import 'package:flutter/material.dart';
import '../../event/ProductContentEvent.dart';
import '../../routers/AppRoutes.dart';
import '../../services/ScreenAdaper.dart';
import '../../widget/BottomDefault.dart';
import '../tabs/TabPage.dart';
import 'TabGoods.dart';
import 'TabGoodsDetail.dart';
import 'TabGoodsEvaluate.dart';

class GoodsDetail extends StatefulWidget {
  Map arguments;

  GoodsDetail({super.key, required this.arguments});

  @override
  _GoodsDetailState createState() => _GoodsDetailState();
}

class _GoodsDetailState extends State<GoodsDetail> {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 3,
      child: Scaffold(
          body: Stack(
            children: [
              TabBarView(
                //处理左右滑动 和 详情 H5页面 手势冲突问题
                physics: const NeverScrollableScrollPhysics(),
                children: [
                  TabGoods(arguments: widget.arguments),
                  TabGoodsDetail(arguments: widget.arguments),
                  TabGoodsEvaluate(arguments: widget.arguments)
                ], // 禁用滑动
              ),
              Positioned(
                  width: ScreenAdapter.getScreenWidth(),
                  bottom: 0,
                  height: ScreenAdapter.height(60),
                  child: Container(
                    decoration: const BoxDecoration(
                        color: Colors.white,
                        border: Border(
                          top: BorderSide(
                            color: Colors.black12,
                            width: 1,
                          ),
                        )),
                    child: Row(
                      children: [
                        InkWell(
                          child: Container(
                              alignment: Alignment.center,
                              width: ScreenAdapter.width(80),
                              child: const Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Icon(Icons.shopping_cart, color: Colors.blue),
                                  Text(
                                    "购物车",
                                    style: TextStyle(fontSize: 12),
                                  )
                                ],
                              )),
                          onTap: () {
                            //跳转到根目录
                            Navigator.of(context)
                                .pushAndRemoveUntil(MaterialPageRoute(builder: (context) => TabPage(currentIndex: 2)), (route) => route == null);
                          },
                        ),
                        Expanded(
                            flex: 1,
                            child: DefaultBottom(
                                color: Colors.blue,
                                text: "加入购物车",
                                cb: () {
                                  eventBus.fire(ProductContentEvent());
                                })),
                        Expanded(
                            flex: 1,
                            child: DefaultBottom(
                                color: Colors.red,
                                text: "立即购买",
                                cb: () {
                                  Navigator.pushNamed(context, AppRoutes.PAY, arguments: {});
                                })),
                      ],
                    ),
                  ))
            ],
          ),
          appBar: AppBar(
            title: const TabBar(
              indicatorColor: Colors.white,
              dividerHeight: 0,
              indicatorSize: TabBarIndicatorSize.label,
              labelColor: Colors.white,
              unselectedLabelColor: Colors.white38,
              tabs: <Widget>[
                Tab(
                  text: "商品",
                ),
                Tab(
                  text: "详情",
                ),
                Tab(
                  text: "评论",
                ),
              ],
            ),
            //右边增加一个 菜单
            actions: [
              IconButton(
                  onPressed: () {
                    showMenu(
                        context: context,
                        position:
                            RelativeRect.fromLTRB(ScreenAdapter.width(600), ScreenAdapter.getStatusBarHeight() + ScreenAdapter.height(50), 0, 0),
                        items: [
                          const PopupMenuItem(
                            child: Text("全部评价"),
                          ),
                          const PopupMenuItem(
                            child: Text("好评"),
                          ),
                          const PopupMenuItem(
                            child: Text("中评"),
                          ),
                        ]);
                  },
                  icon: const Icon(Icons.more_horiz))
            ],
          )),
    );
  }
}
